home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / tu32.zip / TU32DEMO / INDXPROJ / INDXMAIN.PAS < prev    next >
Pascal/Delphi Source File  |  1995-08-03  |  3KB  |  115 lines

  1. unit Indxmain;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Tuidx, DB, DBTables;
  8.  
  9. type
  10.   TFormIndxProjMain = class(TForm)
  11.     IdxUtl1: TIdxUtl;
  12.     OpenDialog1: TOpenDialog;
  13.     ButtonBrowse: TButton;
  14.     EditFileName: TEdit;
  15.     ListBoxStatus: TListBox;
  16.     ButtonCheckIndexes: TButton;
  17.     ButtonRegenIndexes: TButton;
  18.     procedure ButtonBrowseClick(Sender: TObject);
  19.     procedure EditFileNameExit(Sender: TObject);
  20.     procedure ButtonCheckIndexesClick(Sender: TObject);
  21.     procedure IdxUtl1InfoIdxCheck(Sender: TObject; IndexName: String;
  22.       IsUptoDate: Boolean);
  23.     procedure ButtonRegenIndexesClick(Sender: TObject);
  24.     procedure IdxUtl1InfoIdxRegen(Sender: TObject; IndexName: String;
  25.       IsUptoDate: Boolean; var Skip: Boolean);
  26.   private
  27.     { Private declarations }
  28.     Procedure SendToLog(aMsg : String);
  29.   public
  30.     { Public declarations }
  31.   end;
  32.  
  33. var
  34.   FormIndxProjMain: TFormIndxProjMain;
  35.  
  36. implementation
  37.  
  38. {$R *.DFM}
  39.  
  40. Procedure TFormIndxProjMain.SendToLog(aMsg : String);
  41. begin
  42.   With ListBoxStatus do
  43.   begin
  44.     Items.Add(AMsg);
  45.     { This next bit scrolls the text so the most recent msg is visible}
  46.     if (ItemHeight * Items.count) > Height then
  47.       TopIndex:= Items.count - (Height div ItemHeight) ;
  48.   end;
  49.   ListBoxStatus.Refresh;
  50. end;
  51.  
  52. procedure TFormIndxProjMain.ButtonBrowseClick(Sender: TObject);
  53. begin
  54.   if OpenDialog1.Execute then
  55.   begin
  56.     { Set the TableName Name property for the TIdxUtl to be checked }
  57.     IdxUtl1.TableName := OpenDialog1.FileName;
  58.     EditFileName.Text := IdxUtl1.TableName;
  59.   end;
  60. end;
  61.  
  62. procedure TFormIndxProjMain.EditFileNameExit(Sender: TObject);
  63. begin
  64.  if EditFileName.Text = '' then exit;
  65.  { Set the TableName Name property for the TUtility to be checked for corruption }
  66.  IdxUtl1.TableName := ExpandFileName(EditFileName.Text);
  67. end;
  68.  
  69. procedure TFormIndxProjMain.ButtonCheckIndexesClick(Sender: TObject);
  70. begin
  71.   if not IdxUtl1.CheckIndexes then
  72.     MessageDlg('Index(es) are out of date and should be regenerated.',
  73.                  mtWarning, [mbOk], 0);
  74. end;
  75.  
  76. procedure TFormIndxProjMain.IdxUtl1InfoIdxCheck(Sender: TObject;
  77.   IndexName: String; IsUptoDate: Boolean);
  78. begin
  79.   if IsUptoDate then
  80.     SendToLog('Index ' + IndexName + ' is up to date.')
  81.   else
  82.     SendToLog('INDEX ' + Uppercase(IndexName) + ' IS OUT OF DATE.');
  83. end;
  84.  
  85. procedure TFormIndxProjMain.ButtonRegenIndexesClick(Sender: TObject);
  86. begin
  87.   IdxUtl1.RegenIndex;
  88. end;
  89.  
  90. procedure TFormIndxProjMain.IdxUtl1InfoIdxRegen(Sender: TObject;
  91.   IndexName: String; IsUptoDate: Boolean; var Skip: Boolean);
  92. begin
  93.   if IsUptoDate then
  94.   begin
  95.     if MessageDlg(IndexName + ' is not out of date do you want to regenerate it anyway?',
  96.                  mtInformation, [mbYes,mbNo], 0) = mrYes then
  97.     begin
  98.       Skip := False;
  99.       SendToLog(IndexName + ' is being regenerated.');
  100.     end
  101.     else
  102.     begin
  103.       Skip := True;  {this line is not necessary cause Skip is true by default}
  104.       SendToLog(IndexName + ' not out of date and not being regenerated.');
  105.     end;
  106.   end
  107.   else
  108.   begin
  109.     Skip := False; {this line is not necessary cause Skip is false by default}
  110.     SendToLog(IndexName + ' is being regenerated.');
  111.   end;
  112. end;
  113.  
  114. end.
  115.